package homework.hucx.dao;

import homework.hucx.model.Article;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;

public class ArticleDaoImpl implements ArticleDao {

    private JdbcTemplate jdbcTemplate;

    public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
        this.jdbcTemplate = jdbcTemplate;
    }

    @Override
    public void save(Article article) {
        String sql = "insert into t_article values(null,?,?)";
        jdbcTemplate.update(sql,article.getTitle(),article.getContent());
        System.out.println("插入数据："+article);
    }

    @Override
    public void updateTitle(Integer id, String title) {
        String sql = "update t_article set title = ? where id = ?";
        jdbcTemplate.update(sql,title,id);
        System.out.println("修改数据："+id+"号数据的title修改为:"+title);
    }
}
